package com.rainy.guoran.business.manager.services.impl;

import com.rainy.guoran.business.manager.controller.vo.UserSaveReqVO;
import com.rainy.guoran.business.manager.entity.User;
import com.rainy.guoran.business.manager.mapper.UserMapper;
import com.rainy.guoran.business.manager.services.UserService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@AllArgsConstructor
@Service
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;


    @Override
    public Long insertUser(UserSaveReqVO userSaveReqVO) {
        User user = new User();
        BeanUtils.copyProperties(userSaveReqVO, user);
        user.setStatus(1);
        user.setDeleted(false);
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());
        user.setTenantId(1L);
        return userMapper.insertUser(user);
    }

    @Override
    public void updateUser(UserSaveReqVO userSaveReqVO) {
        User user = new User();
        BeanUtils.copyProperties(userSaveReqVO, user);
        user.setUpdateTime(LocalDateTime.now());
        userMapper.updateUser(user);
    }

    @Override
    public User selectUserById(Long id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public void deleteUser(Long id) {
        userMapper.deleteUser(id);
    }
}
